package www.openteam.com.presenter.policy;

import java.util.HashMap;
import java.util.List;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.ProOrder;
import www.openteam.com.contract.policy.PurchaseOrderApprovalContract;
import www.openteam.com.model.policy.PurchaseOrderApprovalModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.policy.PurchaseOrderApprovalFragment;

/**
 * Created by hyd on 2017/1/15.
 */

public class PurchaseOrderApprovalPresenter
        extends BasePresenter<PurchaseOrderApprovalFragment>
    implements PurchaseOrderApprovalContract.PurchaseOrderApprovalPresenter {

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new PurchaseOrderApprovalModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String ,IModel> hashMap = new HashMap<>();
        hashMap.put("queryPrOrder",models[0]);

        return hashMap;
    }

    @Override
    public void queryPrOrder(String rdsno,String code, String orderStart,
                             long startTime, long endTime,String stype,String moreCom, int PageSize) {
        ((PurchaseOrderApprovalModel)
                getiModelMap().get("queryPrOrder"))
                .queryPrOrder(rdsno, code, orderStart, startTime, endTime,stype,moreCom ,PageSize,
                        new PurchaseOrderApprovalModel.PurchaseOrderApprovalOnListener() {
                            @Override
                            public void queryPOASuccess(List<ProOrder.DataEntity> orderApprovals) {
                                getIView().queryPOASuccess(orderApprovals);
                            }

                            @Override
                            public void queryPOAFail(String failMsg) {
                                getIView().queryPOAFail(failMsg);
                            }
                        });
    }

    @Override
    public void unprApprovalUpdate(int id) {
        ( (PurchaseOrderApprovalModel) getiModelMap().get("queryPrOrder"))
                .unprApprovalUpdate(id, new PurchaseOrderApprovalModel.PurchaseOrderUOnListener() {
                    @Override
                    public void unApprovalPOASuccess(ApprovalStatu aprovalStatu) {

                        getIView().unApprovalPOASuccess(aprovalStatu);

                    }

                    @Override
                    public void unApprovalPOAFail(String failMsg) {
                        getIView().unApprovalPOAFail(failMsg);
                    }
                });
    }

    @Override
    public void prApprovalUpdate(int id) {
        ( (PurchaseOrderApprovalModel) getiModelMap().get("queryPrOrder"))
                .prApprovalUpdate(id, new PurchaseOrderApprovalModel.PurchaseOrderAOnListener() {
                    @Override
                    public void approvalPOASuccess(ApprovalStatu aprovalStatu) {
                        getIView().approvalPOASuccess(aprovalStatu);
                    }
                    @Override
                    public void approvalPOAFail(String failMsg) {
                        getIView().approvalPOAFail(failMsg);
                    }
                });
    }
}
